package hotciv.standard.visual;

import java.awt.Point;
import java.awt.event.MouseEvent;

import javax.swing.JTextField;

import hotciv.common.GameImpl;
import hotciv.factories.SemiCivFactory;
import hotciv.framework.Game;
import hotciv.framework.Position;
import hotciv.view.CivDrawing;
import hotciv.view.GfxConstants;
import hotciv.view.MapView;
import hotciv.view.TextFigure;
import minidraw.framework.Drawing;
import minidraw.framework.DrawingEditor;
import minidraw.framework.DrawingView;
import minidraw.framework.Factory;
import minidraw.standard.MiniDrawApplication;
import minidraw.standard.NullTool;

public class ShowGame {
	public static void main(String[] args) {
		Game game = new GameImpl(new SemiCivFactory());

	    DrawingEditor editor = 
	      new MiniDrawApplication( "Click anywhere to see Drawing updates",  
	                               new CivGameFactory(game) );

	    editor.open();
	    editor.setTool( new UpdateTool2(editor, game) );

	    editor.showStatus("Click anywhere to state changes reflected on the GUI");
	    TextFigure tf = new TextFigure(Math.abs(game.getAge())+" BC", new Point(GfxConstants.AGE_TEXT_X, GfxConstants.AGE_TEXT_Y) );                 
	    // Try to set the selection tool instead to see
	    // completely free movement of figures, including the icon

	    // editor.setTool( new SelectionTool(editor) );
	  }
}

/** A tool that simply 'does something' new every time
 * the mouse is clicked anywhere */
class UpdateTool2 extends NullTool {
  private Game game;
  private DrawingEditor editor;
  public UpdateTool2(DrawingEditor editor, Game game) {
    this.editor = editor;
    this.game = game;
  }
  private int count = 0;
  public void mouseDown(MouseEvent e, int x, int y) {
    switch(count) {
    case 0: {
      editor.showStatus( "State change: Moving archer to (1,4)" );
      game.moveUnit( new Position(1,3), new Position(1,4) );
      break;
    }
    case 1: {
      editor.showStatus( "State change: End of Turn (over to blue)" );
      game.endOfTurn();
      break;
    }
    case 2: {
	    editor.showStatus( "State change: Moving legion to (3,3)" );
	    game.moveUnit( new Position(4,4), new Position(3,3) );
	    break;
	  }
    case 3: {
      editor.showStatus( "State change: End of Turn (over to red)" );
      game.endOfTurn();
      break;
    }
    case 4: {
        editor.showStatus( "Selecting archer" );
        game.setTileFocus(new Position(1,4));
        break;
    }
    case 5: {
        editor.showStatus( "Selecting city" );
        game.setTileFocus(new Position(7,7));
        break;
    }
    case 6: {
        editor.showStatus( "Selecting nothing" );
        game.setTileFocus(new Position(0,0));
        break;
    }
    default: {
      editor.showStatus("No more changes in my list...");
    }
    }
    count ++;
  }
}
